package neu.soft.feignclient;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import neu.soft.entity.DO.City;
import neu.soft.entity.Good;
import neu.soft.entity.Vendor;
import neu.soft.vo.ResultBean;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class OperationServerFeignClientFallBackFactory implements FallbackFactory<OperationServerFeignClient> {
    @Override
    public OperationServerFeignClient create(Throwable throwable) {
        return new OperationServerFeignClient() {
            @Override
            public List<Good> findGoods(List<String> code) {
                log.info(throwable.getMessage());
                List<Good> goodList = new ArrayList<>();
                Good good = new Good();
                good.setGoodId("-1");
                goodList.add(good);
                return goodList;
            }

            @Override
            public Vendor getByName(String vendorName) {
                log.info(throwable.getMessage());
                Vendor vendor = new Vendor();
                vendor.setVendorId(0);
                vendor.setNote("查询失败了");
                return vendor;
            }

            @Override
            public ResultBean<City> getInfo(Map<String, Object> map) {
                log.info(throwable.getMessage());
                String cityName = (String) map.get("cityName");
                City city = new City(-1,cityName,"-1","无",null);
                return ResultBean.error("查询失败",city);
            }
        };
    }
}
